package aidlserver.app

object UiHelper {

    private val callbacks: MutableList<Function1<String, Unit>> = mutableListOf()
    private val lock = Any()

    fun addCallback(cbk: Function1<String, Unit>) {
        synchronized(lock) {
            if (!callbacks.contains(cbk)) {
                callbacks.add(cbk)
            }
        }
    }

    fun removeCallback(cbk: Function1<String, Unit>) {
        synchronized(lock) {
            callbacks.remove(cbk)
        }
    }

    fun clear(){
        synchronized(lock){
            callbacks.clear()
        }
    }

    fun invokeCallback(name: String) {
        synchronized(lock) {
            callbacks.forEach {
                it.invoke(name)
            }
        }
    }

}